#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START autoconf

rm -rf build/autoconf
cp -a autoconf build/
cd build/autoconf
reset_mtime autoconf autoconf/configure.ac
cat > config.cache <<-EOF
ac_cv_path_EGREP='/bin/grep -E'
ac_cv_path_EXPR='/usr/bin/expr'
ac_cv_path_GREP='/bin/grep'
ac_cv_path_M4=/usr/bin/m4
ac_cv_path_PERL=/usr/bin/perl
ac_cv_path_SED=/bin/sed
ac_cv_path_install='/bin/install -c'
ac_cv_path_mkdir=/bin/mkdir
ac_cv_perl_flock_implemented=yes
ac_cv_prog_AWK=gawk
ac_cv_prog_EMACS=no
ac_cv_prog_STRIP=/usr/bin/strip
ac_cv_prog_gnu_m4_debugfile=--debugfile
ac_cv_prog_gnu_m4_gnu=yes
ac_cv_prog_make_make_case=yes
ac_cv_prog_make_make_set=yes
ac_cv_sh_n_works=yes
am_cv_make_support_nested_variables=yes
EOF

# XXX: ALT spec builds with
#
# --program-suffix="-${autoconf_version}"
#
# and than play games to arrange the symlink factory
# autoconf -> autoconf-${ver}
# Skip that trickery for now

find -type f -print0 |
	xargs -r0 fgrep -lZ @RPM_AUTOCONF_SUFFIX@ -- |
	xargs -r0 sed -i 's,@RPM_AUTOCONF_SUFFIX@,,' --

# XXX: the above command alters Makefile.{am,in} and causes a spurious
# rebuild of texinfo docs which fails for bizzare reason
reset_mtime . configure.ac

./configure \
	${CONFIGURE_ARGS} \
	--cache-file=config.cache \
	${AUTOCRAP_KLUDGE}

make -j${JOBS}
make -j${JOBS} install DESTDIR="`pwd`/inst"
wipe_la_files `pwd`/inst
mkdir -p inst${prefix}/share/aclocal
cp -a --target-directory=inst${prefix}/share/aclocal m4/m4.m4 # what a nice name
cd inst
find . | cpio -pmdu "$stage"
cd ../../..
rm -rf build/autoconf

# RECIPE END autoconf
